//
//  AYuMainViewController.swift
//  SHWeibo3
//
//  Created by 余伟康 on 16/7/19.
//  Copyright © 2016年 wangce. All rights reserved.
//
//  主体 <框架搭建> 添加四个子控制器

import UIKit

class AYuMainViewController: UITabBarController {


    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = AYuUITabBar()
        tabBar.AYuDelegate = self
        setValue(tabBar, forKey: "tabBar")
        
        // 添加子控制器
        addChildViewController(AYuHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(AYuMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(AYuDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(AYuProfileViewController(), title: "我", imgName: "tabbar_profile")
    }

    /**
     添加子控制器方法-addChildViewController
     
     - parameter vc:      控制器
     - parameter title:   导航栏和tabBar标题
     - parameter imgName: 图片名称
     */
    func addChildViewController(vc:UIViewController,title:String,imgName:String) {

        // 设置导航栏和tabBar的标题
        vc.title = title
        
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        // 选择渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        // 设置颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        // 添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
    
}

// 代理方法
// 撰写按钮点击方法
extension AYuMainViewController:AYuTabBarDelegate {
    func composeButtonClick() {
        let composeView = AYuComposeView()
        composeView.composeViewShow(self)
    }
}



